﻿var report = {
	showFormSwjg:function(menuUuid,swjgUuid,startTime,stopTime){
		if(startTime > stopTime){
			alert("开始日期不能大于结束日期");
			return;
		}
		var html = ''; 
		$.ajax({
			type: "GET",
	        url: config.baseURL + "report/getListMenuById.action",
	        cache:false,
	        async:false,
	        dataType: "json",
	        data : {
				"menuUuid":menuUuid
	        },
	        success: function(data){
	        	$('#tbl_form_swjg').empty();
	        	if(data.result.success==true){
	        		menuhtml = '<table><tr><th>县区局名称</th>';
	        		$.each(data.list, function(index, menu) {
	        			menuhtml += '<th id='+menu[0]+'>'+menu[1]+'</th>';
	        		})
	        		menuhtml += '<th>合　　计</th></tr>';
	        		html += menuhtml;
	        	}
	        }
		});
		$.ajax({
			type: "GET",
	        url: config.baseURL + "report/listSwjgBySuperId.action",
	        cache:false,
	        async:false,
	        dataType: "json",
	        data : {
				"superSwjgUuid":swjgUuid
	        },
	        success: function(data){
	        	if(data.result.success==true){
	        		var swjghtml;
	        		$.each(data.list,function(index,swjg){
	        			swjghtml = '';
	        			swjghtml += '<tr><td id='+swjg[0]+'>'+swjg[1]+'</td>';
	        			$.ajax({
							type: "GET",
					        url: config.baseURL + "report/getListBySwjg.action",
					        cache:false,
					        async:false,
					        dataType: "json",
					        data : {
								"menuUuid":menuUuid,
								"swjgUuid":swjg[0],
					            "startdate":startTime,
					            "stopdate":stopTime
					        },
					        success: function(data){
					        	var totalcount = 0;
					        	if(data.result.success==true){
					        		$.each(data.list,function(index,value){
					        			var dealcount = null == value[2] ? 0 : value[2];
					        			totalcount += dealcount;
					        			if(dealcount == 0){
					        				swjghtml += '<td id=s_'+swjg[0]+'_m_'+value[0]+'>'+dealcount+'</td>';
					        			}else{
					        				swjghtml += '<td id=s_'+swjg[0]+'_m_'+value[0]+'><a href="javascript:report.getDetail('+value[0]+','+swjg[0]+',\''+startTime+'\',\''+stopTime+'\');">'+dealcount+'</a></td>';
					        			}
					        		})
					        		swjghtml += '<th>'+totalcount+'</th></tr>';
					        		html += swjghtml;
					        	}
					        }
						});
	        		})
	        		//html += '</table>';
	        		//$('#tbl_form_swjg').append(html);
	        	}
	        },
	        error:function(){
	        	alert('无法获取税务机构信息');
	        }
		});
		$.ajax({
			type: "GET",
	        url: config.baseURL + "report/getTotal.action",
	        cache:false,
	        dataType: "json",
	        data : {
				"menuUuid":menuUuid,
	            "startdate":startTime,
	            "stopdate":stopTime
	        },
	        success: function(data){
	        	if(data.result.success==true){
	        		totalhtml = '<tr><th>合计</th>';
	        		var total = 0;
	        		$.each(data.list, function(index, value) {
	        			var totalcount = null == value[2] ? 0 : value[2];
	        			totalhtml += '<th id='+value[0]+'>'+totalcount+'</th>';
	        			total += totalcount;
	        		})
	        		totalhtml += '<th>'+total+'</th></tr>';
	        		html += totalhtml;
	        		html += '</table>';
		        	$('#tbl_form_swjg').append(html);
	        	}
	        }
		});
	},
	getDetail:function(menuUuid,swjgUuid,startdate,stopdate){
		$.ajax({
			type: "GET",
	        url: config.baseURL + "report/getDetail.action",
	        cache:false,
	        dataType: "json",
	        data : {
				"menuUuid":menuUuid,
				"swjgUuid":swjgUuid,
	            "startdate":startdate,
	            "stopdate":stopdate
	        },
	        success: function(data){
	        	if(data.result.success==true){
	        		$('#tbl_form_swjg').hide();
	    			$('#tbl_form_swjg_detail').empty().show();
	        		$(window.parent.document).find('#comebackBtn').css('visibility','visible');
	        		//var datahtml = '<table><tr><th width="270">纳税人名称</th><th width="270">受理业务名称</th><th width="90">业务类型</th><th width="70">受理人员</th><th width="130">受理时间</th><th width="120">受理税务机关</th><th width="50">操  作</th></tr>';
	        		var datahtml = '<table><tr><th width="130">纳税人识别号</th><th width="280">纳税人名称</th><th width="270">受理业务名称</th><th width="90">业务类型</th><th width="70">受理人员</th><th width="130">受理时间</th><th width="120">受理税务机关</th></tr>';
	        		$.each(data.list, function(index, value) {
	        			//{"childMenuName":"注销税务登记申请审批表","childMenuUuid":"10","czryName":"白雪","czryUuid":"30","dealtime":{"date":10,"day":4,"hours":14,"minutes":59,"month":0,"nanos":0,"seconds":55,"time":1357801195000,"timezoneOffset":-480,"year":113},"formId":"1123","id":1124,"menuName":"税务登记","menuUuid":"2","nsrmc":"酒泉金道贵金属投资咨询有限公司","nsrsbh":"622102585947354","swjgName":"肃州区国家税务局","swjgUuid":"127"}
	        			//datahtml += '<tr><td>'+value.nsrmc+'</td><td>'+value.childMenuName+'</td><td>'+value.menuName+'</td><td>'+value.czryName+'</td><td>'+new Date(value.dealtime.time).format('yyyy-MM-dd hh:mm:ss')+'</td><td>'+value.swjgName+'</td><td><a id="a_'+(index+1)+'" onclick="report.getFormById('+(index+1)+','+value.childMenuUuid+','+value.formId+');" class="a_form_detail" style="color:blue;cursor:pointer;">明 细</a></td></tr>';
	        			datahtml += '<tr><td>'+value.nsrsbh+'</td><td>'+value.nsrmc+'</td><td>'+value.childMenuName+'</td><td>'+value.menuName+'</td><td>'+value.czryName+'</td><td>'+new Date(value.dealtime.time).format('yyyy-MM-dd hh:mm:ss')+'</td><td>'+value.swjgName+'</td></tr>';
	        		});
	        		datahtml += '</table>';
	        		$('#tbl_form_swjg_detail').append(datahtml);
	        	}
	        }
		});
	},
	getFormById:function(index,childMenuId,formId){
		$.ajax({
			type: "GET",
	        url: config.baseURL + "report/getFormById.action",
	        cache:false,
	        dataType: "json",
	        data : {
				"formId":childMenuId //小类业务ID
	        },
	        success: function(data){
	        	if(data.result.success==true){
	        		$('#a_'+index).attr('href',config.baseURL+'forms/'+data.list[0]);
	        		$('#a_'+index).colorbox({iframe:true, width:200, height:500})
	        		return;
	        		$.ajax({
			            type: "GET",
			            url: config.baseURL + "common/sendHttp.action",
			            cache:false,
			            dataType: "xml",
			            data : {
			                "url":config.interfaceCenterBaseURL + "/interface/getTaxpayerInfo.action",
			                "taxpayer":formId,
			                "typeId":childMenuId
			            },
			            success: function(xml){
			            	$(xml).find("resultInfo").each(function(i){
			                    var name = $(this).attr("name");
			                    var value = $(this).text();
			                    $('#'+name, document.frames('formPage').document).val(value); 
			                    $('#'+name, document.frames('formPage').document).removeClass('placeholder');
			                    if(name=='nsrsbh'){
			                		if($('#nsrsbhTr',document.frames('formPage').document).attr('size') > 0){
			                    		for(var i=0;i<value.length;i++){
			                    			$('#nsrsbhTd'+(i+1),document.frames('formPage').document).text(value.substr(i,1));
			                    		}
			                    	}
			                    }
			                });
			            },
			            error:function(){
			            	alert('error');
			            }
		       		});
	        	}
	        }
		});
	},
	comeBack:function(){
		$(window.parent.document).find('#comebackBtn').css('visibility','hidden');
		$('#tbl_form_swjg').show();
	    $('#tbl_form_swjg_detail').empty();
	},
	changeDiv:function(num){
		if(num == 1){
			$('#tb2_form_swjg').hide();
			$('#tbl_form_swjg_detail').empty();
			$('#tbl_form_swjg').show();
		}else if(num == 2){
			$(window.parent.document).find('#comebackBtn').css('visibility','hidden');
			$('#tbl_form_swjg').hide();
			$('#tbl_form_swjg_detail').empty();
			$('#tb2_form_swjg').show();
		}
	},
	getFormDetail:function(){
		$(".a_mx").colorbox({iframe:true, width:200, height:500});
	}
};

function initSjd(menuUuid,swjgUuid,startdate,stopdate){
	$.ajax({
		type: "GET",
        url: config.baseURL + "report/getListBySjd.action",
        cache:false,
        dataType: "json",
        data : {
			"menuUuid":menuUuid,
			"swjgUuid":swjgUuid,
            "startdate":startdate,
            "stopdate":stopdate
        },
        success: function(data){
        	if(data.result.success==true){
        		alert('ok');
        	}
        }
	});
}

function initCzry(menuUuid,swjgUuid,startdate,stopdate){
	
	$.ajax({
		type: "GET",
        url: config.baseURL + "report/getListByCzry.action",
        cache:false,
        dataType: "json",
        data : {
			"menuUuid":menuUuid,
			"swjgUuid":swjgUuid,
            "startdate":startdate,
            "stopdate":stopdate
        },
        success: function(data){
        	if(data.result.success==true){
        		alert('ok');
        	}
        }
	});
}

function initListSwjg(swjgUuid){
	$.ajax({
		type: "GET",
        url: config.baseURL + "report/listSwjgBySuperId.action",
        cache:false,
        dataType: "json",
        data : {
			"superSwjgUuid":swjgUuid
        },
        success: function(data){
        	if(data.result.success==true){
        		alert('ok');
        	}
        },
        error:function(){
        	alert();
        }
	});
}

function initListMenu(menuUuid){
	$.ajax({
		type: "GET",
        url: config.baseURL + "report/getListMenuById.action",
        cache:false,
        dataType: "json",
        data : {
			"menuUuid":menuUuid
        },
        success: function(data){
        	if(data.result.success==true){
        		var html = '<table><tr><th>县区局名称</th>';
        		$.each(data.list, function(index, menu) {
        			html += '<th id='+menu[0]+'>'+menu[1]+'</th>';
        		})
        		$('#tbl_from_swjg').append(html);
        	}
        }
	});
}

function changeDiv(num){
	if(num == 1){
		$('#tb2_form_swjg').hide();
		$('#tbl_form_swjg').show();
	}else if(num == 2){
		$('#tbl_form_swjg').hide();
		$('#tb2_form_swjg').show();
	}
}

function getFormById(formId,tableId){
	$.ajax({
		type: "GET",
        url: config.baseURL + "report/getFormById.action",
        cache:false,
        dataType: "json",
        data : {
			"formId":formId
        },
        success: function(data){
        	if(data.result.success==true){
        		//alert(data.list[0]);
        	}
        }
    });
}